package com.kfirszt.elearning.persistence.model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;

import com.kfirszt.elearning.dictionary.Ability;
import com.kfirszt.elearning.dictionary.CharacterTrait;
import com.kfirszt.elearning.dictionary.Interest;
import com.kfirszt.elearning.dictionary.Sex;

@Entity
@Table(name = "student")
public class Student extends BaseUser {

	private static final long serialVersionUID = 1L;
	
	@Column(name = "age")
	private Integer age;
	
	@ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.DETACH})
	@JoinColumn(name = "city_id")
	private City city;
	
	@Column(name = "knowledge_degree")
	private String knowledgeDegree; //?
	
	@Column(name = "_class")
	private Integer _class;
	
	@Column(name = "sex")
	@Enumerated(EnumType.STRING)
	private Sex sex;
	
	@ElementCollection(targetClass = Ability.class)
	@CollectionTable(name = "student_ability")
	@Enumerated(EnumType.STRING)
	@Column(name = "ability_id")
	private List<Ability> abilities = new ArrayList<Ability>();
	
	@ElementCollection(targetClass = CharacterTrait.class)
	@CollectionTable(name = "student_character_trait")
	@Enumerated(EnumType.STRING)
	@Column(name = "character_trait_id")
	private List<CharacterTrait> characterTraits = new ArrayList<CharacterTrait>();
	
	@ElementCollection(targetClass = Interest.class)
	@CollectionTable(name = "student_interest")
	@Enumerated(EnumType.STRING)
	@Column(name = "interest_id")
	private List<Interest> interests = new ArrayList<Interest>();
	
	@Override
	public Collection<GrantedAuthority> getAuthorities() {
		List<GrantedAuthorityImpl> authorityImpls = new ArrayList<GrantedAuthorityImpl>();
		authorityImpls.add(new GrantedAuthorityImpl("ROLE_STUDENT"));
		Collection<GrantedAuthority> authorities = super.getAuthorities();
		authorities.addAll(authorityImpls);
		return authorities;
	}

	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	public City getCity() {
		return city;
	}

	public void setCity(City city) {
		this.city = city;
	}

	public String getKnowledgeDegree() {
		return knowledgeDegree;
	}

	public void setKnowledgeDegree(String knowledgeDegree) {
		this.knowledgeDegree = knowledgeDegree;
	}

	public Integer get_class() {
		return _class;
	}

	public void set_class(Integer _class) {
		this._class = _class;
	}

	public List<Ability> getAbilities() {
		return abilities;
	}

	public void setAbilities(List<Ability> abilities) {
		this.abilities = abilities;
	}

	public List<CharacterTrait> getCharacterTraits() {
		return characterTraits;
	}

	public void setCharacterTraits(List<CharacterTrait> characterTraits) {
		this.characterTraits = characterTraits;
	}

	public List<Interest> getInterests() {
		return interests;
	}

	public void setInterests(List<Interest> interests) {
		this.interests = interests;
	}

	public Sex getSex() {
		return sex;
	}

	public void setSex(Sex sex) {
		this.sex = sex;
	}
}
